# -*- coding: UTF-8 -*-

import itchat
import time
import uuid


def send_message():
    itchat.auto_login(True)
    author = itchat.search_friends(nickName='')[0]
    for i in range(0, 10000):
        author.send('greeting, littlecoder!')


def send_room_message():
    itchat.auto_login(True)
    chat_room_list = itchat.get_chatrooms(update=True)
    user_name = ''

    for chat_room in chat_room_list:
        if chat_room['NickName'] == u'午饭茶话会':
            user_name = chat_room['UserName']

    while True:
        time.sleep(1)
        itchat.send(str(uuid.uuid4()), user_name)


def send_to_file_assistant(message):
    receiver = itchat.search_friends(nickName="文件传输助手")
    receiver.send(message)


def receive_message():
    @itchat.msg_register(itchat.content.TEXT)
    def text_reply(msg):
        send_to_file_assistant(msg)

    itchat.auto_login(True)
    itchat.run()


def receive_group_message():
    @itchat.msg_register(itchat.content.TEXT, isGroupChat=True)
    def text_reply(msg):
        if msg.isAt:
            msg.user.send(u'@%s\u2005I received: %s' % (
                msg.actualNickName, msg.text))

    itchat.auto_login(True)
    itchat.run()


if __name__ == '__main__':
    send_room_message()
